#!/bin/bash

# Test manual recovery command

. ./common

for i in `seq 0 7`; do
    _start_sheep $i
done

_wait_for_sheep 8

_cluster_format -c 6
$DOG cluster recover disable

_vdi_create test 4G

# create 8 objects
for i in `seq 0 7`; do
    echo $i | $DOG vdi write test $((i * 4 * 1024 * 1024)) 512
done

_kill_sheep 3
_kill_sheep 4

_wait_for_sheep 6

# overwrite the objects to invoke object recovery
for i in `seq 4 7`; do
    $DOG vdi read test $((i * 4 * 1024 * 1024)) 512 | md5sum
    echo $(($i + 100)) | $DOG vdi write test $((i * 4 * 1024 * 1024)) 512
done

$DOG cluster recover enable
_wait_for_sheep_recovery 0
$DOG cluster info | head -6 | _filter_cluster_info
ls $STORE/*/{obj,d[0-9]*}/* 2> /dev/null | \
	_filter_store | _filter_md_store | sort

$DOG cluster recover disable
for i in 3 4; do
    _start_sheep $i
done

_wait_for_sheep 8

# overwrite the objects to invoke object recovery
for i in `seq 0 3`; do
    $DOG vdi read test $((i * 4 * 1024 * 1024)) 512 -p 7007 | md5sum
    echo $(($i + 200)) | $DOG vdi write test $((i * 4 * 1024 * 1024)) 512
done

$DOG cluster recover enable
_wait_for_sheep_recovery 0
$DOG cluster info | head -6 | _filter_cluster_info
ls $STORE/*/{obj,d[0-9]*}/* 2> /dev/null | \
	_filter_store | _filter_md_store | sort
$DOG vdi read test 0 32m | md5sum
